package com.lida.study.web.controller;

import com.lida.study.common.utils.opencv.OpenCvUtils;
import com.lida.study.sudo.Sudo;
import com.lida.study.sudo.SudoRun;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lD
 * @date 2019/7/1013:49
 */
@Controller
@RequestMapping("sudo")
public class SudoController {

    @GetMapping("index")
    public String index() {
        return "/sudo/index";
    }

    @PostMapping("getSudo")
    @ResponseBody
    public Sudo getSudo(String fileName) {
        if (StringUtils.isEmpty(fileName)) {
            return null;
        }
        return OpenCvUtils.openCvDeal(fileName);
    }

    @PostMapping("getSudoAnswer")
    @ResponseBody
    public List<Sudo> getSudoAnswer(@RequestBody Sudo sudo) {
        if (sudo == null) {
            return new ArrayList<>();
        }
        return new SudoRun().run(sudo);
    }
}
